<template>
	<view v-if="info==''">
		<xbd-zwnz marginTop='200'></xbd-zwnz>
	</view>
	<view v-else class="center">
		<xbd-page-card>
			<template>
				<view>
					<xbd-image-title :title="info.task_name" :image="require('@/static/image/supervision/jdh.png')">
					</xbd-image-title>
					<view class="tag">
						督查单位
					</view>
					<view class="text">
						{{info.enclosure}}
					</view>
					<view class="tag">
						上报人
					</view>
					<view class="text">
						{{info.report_person[0]}}
					</view>
					<view class="tag">
						上报时间
					</view>
					<view class="text">
						{{info.report_time | timeFormat('YYYY-MM-DD HH:mm')}}
						<text v-if="(info.report_time>info.end_time)" class="text-color" >超时</text>
					</view>
					<view class="tag">
						计划描述
					</view>
					<view class="text">
						{{info.plan_desc}}
					</view>
					<view class="tag">
						督查结果
					</view>
					<!-- 富文本编译插件 -->
					<parser v-if="info.result" :html="info.result" :tagStyle='style' />
					<view v-else>
						<view v-if="info.app_img.length!==0 " class="image" >
							<image v-for="(item,index) in info.app_img" :key="index" :src="item" @click="image_click(item)"></image>
						</view>
						<view class="text">
							{{info.app_string||'-'}}
						</view>
					</view>
					<view class="tag">
						任务时间
					</view>
					<view class="time">
						{{info.start_time | timeFormat('YYYY-MM-DD HH:mm')}}
						<view class="to">
							至
						</view>
						<text v-if="nowDate>timeFormat(info.end_time)" style="color: #FC4F4F;">
							{{info.end_time | timeFormat('YYYY-MM-DD HH:mm')}}
						</text>
						<text v-else>{{info.end_time | timeFormat('YYYY-MM-DD HH:mm')}}</text>
					</view>
				</view>
			</template>
		</xbd-page-card>

		<!-- 已审批 查看 -->
		<xbd-page-card v-if="info.state!=='pending' &&  info.state!=='wait'">
			<template>
				<view class="center_box">
					<image v-if="info.state === 'refused'" class="img" src="@/static/image/supervision/refused.png">
					</image>
					<image v-if="info.state === 'successed'" class="img" src="@/static/image/supervision/pass.png">
					</image>
					<view class="tag">
						审核人
						<text class="back" v-if="info.state==='break'">
							已退回
						</text>
					</view>
					<view class="text">
						{{info.last_audit}}
					</view>
					<view class="tag">
						审核意见
					</view>
					<view class="text">
						{{info.view||'-'}}
					</view>
					<view class="tag">
						审核时间
					</view>
					<view class="text">
						{{info.audit_time | timeFormat('YYYY-MM-DD HH:mm')}}
					</view>
				</view>
			</template>
		</xbd-page-card>
		<!-- 审核 -->
		<xbd-page-card v-if="info.state==='pending'">
			<template>
				<view>
					<view class="tag">
						审核人
					</view>
					<view class="text">
						{{userInfo.name}}
					</view>
					<view class="tag">
						审核意见
					</view>
					<textarea class="textarea" placeholder="请输入内容..." v-model="o.view" maxlength="-1"
						auto-height></textarea>
				</view>
			</template>
		</xbd-page-card>
		<xbd-popup :isShow="showDialog" @dialogConfirm="dialogConfirm" @dialogCancel="dialogCancel" :content="msg"
			cancelText="取消" confirmText="确定"></xbd-popup>
		<view v-if="info.state==='pending'" class="floot">
			<view class="btn refused" @click="click('refused')">
				拒绝
			</view>
			<view class="btn back" @click="click('break')">
				退回
			</view>
			<view class="btn pass" @click="click('successed')">
				通过
			</view>
		</view>
	</view>

</template>

<script>
	import parser from '@/components/jyf-parser/jyf-parser.vue';
	import {
		mapState
	} from 'vuex';
	import {
		Supervision
	} from '@/api/index.js';
	const dayjs = require("dayjs");
	export default {
		components: {
					parser
				},
		data() {
			const nowDate = dayjs(new Date()).format('YYYY-MM-DD HH:mm:ss')
			return {
				showType:false,
				// value: "",
				nowDate: nowDate,
				id: '',
				showDialog: false,
				flag: true,
				info: '',
				msg: '',
				style: {
					'img': 'display:block;margin: 0 auto;max-width:100%;height:auto; transform: translateX(0);',
					'video': 'width:100%;height:auto;',
				},
				o: {
					id: '',
					view: '',
					state: ''
				}
			}
		},
		computed: {
			...mapState(['userInfo'])
		},
		methods: {
			timeFormat(time){
			    return dayjs(time).format('YYYY-MM-DD HH:mm:ss');
			},
			image_click(val) {
				// 点击预览图片
				dd.previewImage({
					current: 1,
					urls: [val],
				});
			},
			click(val) {
				if (val === 'refused') {
					this.o.state = 'refused'
					this.msg = '确定审核结果为拒绝？'
				} else if (val === 'break') {
					this.o.state = 'break'
					this.msg = '确定审核结果为退回？'
				} else {
					this.o.state = 'successed'
					this.msg = '确定审核结果为通过？'
				}
				this.showDialog = true
			},
			dialogConfirm() {
				console.log('确认')
				this.flag = false
				this.Audit()
				this.showDialog = false
			},
			dialogCancel() {
				this.showDialog = false
			},
			async Audit() {
				const res = await Supervision.postCircularAudit(this.o)
				if (!res.success) {
					this.flag = true
				}else{
					setTimeout(() => {
						uni.navigateBack({
							delta: 1
						});
					}, 1500)
				}
				this.$showToast(res.msg);
				console.log(res, 'res')
			},
			async init() {
				const res = await Supervision.getAuditDetail(this.id)
				if(res.success){
					this.showType=true
					this.info = res.data
				}else{
					this.$showToast(res.msg);
				}
				console.log(this.info, 'this.info')
			}
		},
		async onLoad(res) {
			this.id = res.id
			this.o.id = res.id
			console.log(res)
			await this.init()
		}
	}
</script>

<style lang="scss" scoped>
	.center {

		padding: 32rpx;
		font-size: 30rpx;
		line-height: 52rpx;

		.center_box {
			position: relative;

			.img {
				position: absolute;
				right: 30rpx;
				top: 40rpx;
				width: 116rpx !important;
				height: 100rpx !important;

			}
		}

		.tag {
			color: #A0A7B8;
			font-size: 26rpx;

			// margin-bottom: 20rpx;
			.back {
				color: #FFFFFF;
				padding: 3rpx 6rpx;
				margin-left: 30rpx;
				background-color: #FC4F4F;
				font-size: 22rpx;
				border-radius: 6rpx;
			}
		}

		.text {
			margin-bottom: 20rpx;
			 white-space: pre-line !important;
			 word-break: break-all !important;
			 word-wrap: break-word ;
			 
			.text-color {
				margin-left: 20rpx;
				padding: 3rpx 6rpx;
				background: rgba(252, 185, 79, 0.15);
				border-radius: 4rpx;
				color: #FCB94F;
			}

			.back {
				color: #FFFFFF;
				padding: 3rpx 6rpx;
				margin-left: 30rpx;
				background-color: #FC4F4F;
				font-size: 22rpx;
				border-radius: 6rpx;
			}
		}

		.image {
			display: flex;
			flex-wrap: wrap;
			margin-top: 20rpx;

			image {
				width: 160rpx;
				height: 160rpx;
				margin-right: 20rpx;
				margin-bottom: 20rpx;
			}

			.upload {

				display: flex;
				justify-content: center;
				flex-direction: column;
				align-items: center;
				font-size: 20rpx;
				color: #A0A7B8;
				width: 140rpx;
				height: 140rpx;
				border: 2rpx dashed #d0d6e5;
				border-radius: 8rpx;
				line-height: normal;

				image {
					width: 28rpx;
					height: 28rpx;
					margin-right: 0;
					margin-bottom: 10rpx;
				}
			}
		}

		.time {
			display: flex;
			font-size: 30rpx;
			.to {
				margin: 0 10rpx;
			}
		}

		.textarea {
			min-height: 160rpx;
			padding: 20rpx 30rpx;
			font-size: 30rpx;
			border: 2rpx solid #EBEEF5;
			margin-bottom: 20rpx;
			border-radius: 8rpx;
		}

		.floot {
			margin-top: 60rpx;
			display: flex;
			justify-content: space-between;

			.btn {
				display: flex;
				justify-content: center;
				align-items: center;
				width: 200rpx;
				height: 90rpx;
				font-size: 32rpx;
				border-radius: 8rpx;
			}

			.refused {
				border: 2rpx solid #FC4F4F;
				color: #FC4F4F;
			}

			.back {
				border: 2rpx solid #FCB94F;
				color: #FCB94F;
			}

			.pass {
				background: linear-gradient(266deg, #2e73fc 3%, #1ea9fb 95%);
				// border: 2rpx solid #FC4F4F;
				color: #FFFFFF;
			}
		}
	}
</style>
